package com.auxgroup.hr.front.service.modperson.impl;

import java.sql.Timestamp;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.auxgroup.hr.front.service.hireperson.impl.HireEducatServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import com.auxgroup.hr.front.commons.utils.ObjectFieldUtils;
import com.auxgroup.hr.front.commons.vo.UserDTO;
import com.auxgroup.hr.front.dao.domain.PsCModPerPrimary;
import com.auxgroup.hr.front.dao.domain.PsCModWorkHi;
import com.auxgroup.hr.front.dao.repository.PsCModWorkHiRepository;
import com.auxgroup.hr.front.service.modperson.ModWorkHiService;

/** 
 * @author lvliuhao
 * @version 创建时间：180526 
 * 工作经历流程信息service
 */
@Service("modWorkHiService")
public class ModWorkHiServiceImpl implements ModWorkHiService {
	private static final Logger logger = LoggerFactory.getLogger(HireEducatServiceImpl.class);
	
	@Autowired
	private PsCModWorkHiRepository PsCModWorkHiRepository;
	
	@Override
	public PsCModWorkHi getModWorkHi(PsCModPerPrimary modPerPrimary) {
		return PsCModWorkHiRepository.findOne(modPerPrimary);
	}


	@Override
	public PsCModWorkHi save(PsCModWorkHi ModWorkHi,UserDTO user) {
		ModWorkHi.setHrsRowAddOprid(user.getOprId());
		ModWorkHi.setHrsRowAddDttm(new Timestamp(System.currentTimeMillis()));
		ModWorkHi.setHrsRowUpdOprid(user.getOprId());
		ModWorkHi.setHrsRowUpdDttm(new Timestamp(System.currentTimeMillis()));
		Set<String> ignoreFields = new HashSet<String>(Arrays.asList("cSeqno"));
		ObjectFieldUtils.handleNullValue(ModWorkHi,ignoreFields);
		return PsCModWorkHiRepository.save(ModWorkHi);
	}


	@Override
	public Boolean delete(PsCModPerPrimary modPerPrimary) {
		try {
			PsCModWorkHiRepository.delete(modPerPrimary);
		} catch (Exception e) {
			logger.error("delete ModWorkHi error: modPerPrimary={}",modPerPrimary,e);
			return false;
		}
		return true;
	}
	
	
	@Override
	public List<PsCModWorkHi> getAll(String emplId) {
		PsCModWorkHi ModWorkHi = new PsCModWorkHi();
		ModWorkHi.setEmplid(emplId);
		return PsCModWorkHiRepository.findAll(Example.of(ModWorkHi));
	}

	/* (non-Javadoc)
	 * @see ModWorkHiService#getAll(java.lang.String, java.lang.String)
	 */
	@Override
	public List<PsCModWorkHi> getAll(String cTransactionNbr, String emplId) {
		PsCModWorkHi ModWorkHi = new PsCModWorkHi();
		ModWorkHi.setEmplid(emplId);
		ModWorkHi.setcTransactionNbr(cTransactionNbr);
		return PsCModWorkHiRepository.findAll(Example.of(ModWorkHi));
	}
	
}
